package com.lianqi.emcpframework.dataaccess.configurer;

import java.util.List;

import javax.servlet.http.HttpSessionListener;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.lianqi.emcpframework.dataaccess.DataAccessContextHolder;
import com.lianqi.emcpframework.dataaccess.DataAccessContextSupplier;
import com.lianqi.emcpframework.dataaccess.supplier.SimpleDataAccessContextSupplier;

/**
 * @program emcp-framework
 * @ClassName AuthenticationConfigurer
 * @description: 数据权限参数化处理配置
 * @author: sky
 * @create: 2019/05/29 18:32
 */
@Configuration
public class ArgumentResolverConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(new DataAccessArgumentResolver());
    }

    @Bean
    public DataAccessContextSupplier authenticationSupplier() {
        DataAccessContextSupplier supplier = new SimpleDataAccessContextSupplier();
        DataAccessContextHolder.addSupplier(supplier);
        return supplier;
    }

    @Bean
    public ServletListenerRegistrationBean<HttpSessionListener> dataAccessSessionListener() {
        return new ServletListenerRegistrationBean<>(new DataAccessSessionListener());
    }
}
